<!DOCTYPE html>
<html>
<head><meta charset="utf-8"/>
<meta name="renderer" content="webkit|ie-stand"/>
<meta http-equiv="X-UA-Compatible" content="IE=11;IE=10;IE=9;IE=edge,chrome=1"/>
<meta name="viewport" content="initial-scale=1.0, width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<meta name="format-detection" content="telephone=no, email=no"/>
<meta name="msapplication-tap-highlight" content="no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<meta name="x5-page-mode" content="app"/>
<meta name="browsermode" content="application"/>
<meta name="wap-font-scale" content="no"/>
<meta name="author" content="feilong.org"/>
<title>D:/xampp/htdocs/work/study/2023基础测试/</title>
</head>
<body>


<a id="aaa" href="" target="_blank">解构.html</a>
<p id="demo"></p>

<script>

 aaa.href=document.title + aaa.innerHTML;
  
  var arr = [1,2,3]
  var arr2 = [...arr];
  
  console.log('=',arr==arr2);  // false  拷贝出一个新的数组/对象  内容一样
  console.log('=',arr===arr2); // false   
  console.log('=',arr2); // [1,2,3]
  
  // 拷贝出来的对象/数组  和原对象/数组是两个不同的对象/数组
  // 修改原数据还是新数据  里面是简单数据 就是深拷贝  里面是复杂数据 浅拷贝
  var a = [1,2,{username:'liubei'}]
  var b = [...a]  // 深拷贝
  //b.push(4);
  //b[2].username = 'zhangfei'
  //console.log('a=',a);  // [1,2,{username:'zhangfei'}]
  //console.log('b=',b);  // [1,2,{username:'zhangfei'},4]
  
  a.push(23)
  a[2].username = 'zhangfei'
  console.log('a=',a);  // [1,2,{username:'zhangfei'},23]
  console.log('b=',b);  // [1,2,{username:'zhangfei'}]
  
let obj = {
  name:'hello',
  cars:['宝马','大众']
}

let obj2 = { ...obj }
//obj.cars[0] = '法拉利'
//obj.name = 'yaoming'
//console.log('obj=',obj);    //  { name:'yaoming', cars:['法拉利','大众']  }
//console.log('obj2=',obj2);  //  { name:'hello', cars:['法拉利','大众']  }

obj2.name ='guanyu' 
obj2.cars[0] = '劳斯莱斯'
console.log('obj=',obj);    //  { name:'hello',  cars:['劳斯莱斯','大众']  }
console.log('obj2=',obj2);  //  { name:'guanyu', cars:['劳斯莱斯','大众']  }
  

</script>
</body>
</html>
